﻿Imports System.Drawing.Drawing2D
Public Class compass

    Public Function rotateImage(ByVal bitmap As Bitmap, ByVal angle As Single) As Bitmap
        Dim returnBitmap As New Bitmap(bitmap.Width, bitmap.Height)
        Dim graphics__1 As Graphics = Graphics.FromImage(returnBitmap)
        graphics__1.TranslateTransform(CSng(bitmap.Width) / 2, CSng(bitmap.Height) / 2)
        graphics__1.RotateTransform(-angle)
        graphics__1.TranslateTransform(-CSng(bitmap.Width) / 2, -CSng(bitmap.Height) / 2)
        graphics__1.DrawImage(bitmap, New Point(10, 10))
        Return returnBitmap
    End Function



    Public Sub tick(ByVal dir)
       
        PictureBox1.Image = rotateImage(My.Resources.compas_t16023, dir)
        TextBox2.Text = dir & "°"
        If dir < 40 Then
            Label2.Text = "N"
        End If
        If dir < 90 And dir > 45 Then
            Label2.Text = "NE"
        End If
        If dir < 135 And dir > 90 Then
            Label2.Text = "E"
        End If
        If dir < 180 And dir > 135 Then
            Label2.Text = "SE"
        End If
        If dir < 225 And dir > 180 Then
            Label2.Text = "S"
        End If
        If dir < 270 And dir > 225 Then
            Label2.Text = "SW"
        End If
        If dir < 315 And dir > 270 Then
            Label2.Text = "W"
        End If
        If dir < 330 And dir > 315 Then
            Label2.Text = "NW"
        End If
        If dir < 361 And dir > 330 Then
            Label2.Text = "N"
        End If
    End Sub



   

    Private Sub compass_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.TopMost = True
    End Sub
End Class